package cn.tedu.net.collection.seri;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

//本类用来测试编码转换流
//编写时的编码与查看时的编码一致才不会乱码
public class Test2_Encode {
    public static void main(String[] args) {
        //1.创建流对象
        OutputStreamWriter out=null;
        try {
            //out= new OutputStreamWriter(new FileOutputStream("1.txt"));//不是磁盘路径,直接生成在项目下
            //out= new OutputStreamWriter(new FileOutputStream("1.txt"),"ISO-8859-1");//不是磁盘路径,直接生成在项目下
            out= new OutputStreamWriter(new FileOutputStream("1.txt"),"UTF-8");//不是磁盘路径,直接生成在项目下
            //通过流对象输出数据到1.txt中
            out.write("我们可以的~马上要干饭了");
            System.out.println("成功");
        } catch (Exception e) {
            System.out.println("失败");
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
